<?php
class EventCategoriesController extends EventsAppController {

	var $name = 'EventCategories';
	var $helpers = array('Html', 'Form','Cms.Index');
	var $components = array('Auth','Session','RequestHandler');
	protected $autoAdminActions = array('admin_bulkDelete');

	function beforeFilter()
	{
		$this->Auth->allow('index','view');
		parent::beforeFilter();
	}

	function index() {
		$this->pageTitle = __('Event Categories');
		$this->paginate['limit'] = 10;
		$this->paginate['recursive'] = 0;
		$this->EventCategory->recursive = 0;
		$this->set('eventCategories', $this->paginate());
	}

	function view($id = null) 
	{
		$eventCategory = $this->EventCategory->read(null, $id);
		if (!$id || empty($eventCategory))
		{
			$this->errorMsg(__('Invalid event category', true));
			$this->redirect(array('controller'=>'event_categories','action' => 'index'));
		}
		$this->set('eventCategory', $eventCategory);
		$this->pageTitle = $eventCategory['EventCategory']['name'];
	}

	function admin_index() 
	{
		$this->pageTitle = __('Event Categories');
		//$this->helpers[] = 'Tree';
		$this->paginate['limit'] = 10;
		$this->paginate['recursive'] = 0;
		$this->EventCategory->recursive = 0;
		$this->set('eventCategories', $this->paginate());
	}

	function admin_view($id = null) 
	{
		$eventCategory = $this->EventCategory->read(null, $id);
		if (!$id || empty($eventCategory)) 
		{
			$this->errorMsg(__('Invalid event category', true));
			$this->redirect(array('controller'=>'event_categories','action'=>'admin_index'));
		}
		$this->set('eventCategory', $eventCategory);
		$this->pageTitle = $eventCategory['EventCategory']['name'];
	}

	function admin_add() 
	{
		$this->pageTitle = __('Add Event Category');
		if (!empty($this->data))
		{
			if(isset($this->data['EventCategory']['name']) && !empty($this->data['EventCategory']['name']))
			{
				$this->data['EventCategory']['slug'] = Inflector::slug($this->data['EventCategory']['name'],"_");
				$this->data['EventCategory']['name'] = ucwords($this->data['EventCategory']['name']);
			}
			$this->EventCategory->create();
			if ($this->EventCategory->save($this->data)) {
				$this->successMsg(__('The event category has been saved', true));
				$this->redirect(array('controller'=>'event_categories','action'=>'admin_index'));
			} else {
				$this->errorMsg(__('The event category could not be saved. Please, try again.', true));
			}
		}
	}

	function admin_edit($id = null) 
	{
		$this->pageTitle = __('Edit Event Category');
		$eventCategory = $this->EventCategory->read(null, $id);
		if (!$id || empty($eventCategory))
		{
			$this->errorMsg(__('Invalid event category.', true));
			$this->redirect(array('controller'=>'event_categories','action'=>'admin_index'));
			return;
		}
		if (!empty($this->data)) 
		{
			$this->data['EventCategory']['id'] = $id;
			if ($this->EventCategory->save($this->data)) {
				$this->successMsg(__('The event category has been saved', true));
				$this->redirect(array('controller'=>'event_categories','action'=>'admin_index'));
			} else {
				$this->errorMsg(__('The event category could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) 
		{
			$this->EventCategory->recursive = -1;
			$this->data = $eventCategory;
		}

	}

	function admin_delete($id = null) 
	{
		$eventCategory = $this->EventCategory->read(null, $id);
		if (!$id || empty($eventCategory))
		{
			$this->errorMsg(__('Invalid URL', true));
			$this->redirect(array('controller'=>'event_categories','action'=>'admin_index'));
			return;
		}
		if ($this->EventCategory->del($id)) {
			$this->successMsg(__('Event category deleted', true));
		} else {
			$this->errorMsg(__('The event category could not be deleted. Please, try again.', true));
		}
		$this->redirect(array('controller'=>'event_categories','action'=>'admin_index'));
	}

}
?>